﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace _1stVATCWed
{
    public partial class LienHe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public static bool isValidEmail(string inputEmail)
        {
            string strRegex = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
            //string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
            //      @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
            //      @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputEmail))
                return (true);
            else
                return (false);
        }  

        protected void Button1_Click(object sender, EventArgs e)
        {
            lienheloi.Text = "";
            if (tenkhachhang.Text == "" || email.Text == "" || tieude.Text == "" || noidung.Text == "")
            {
                lienheloi.Text = "Xin nhập đầy đủ dữ liệu";
            }
            else
            {
                lienheloi.Text = "Đã nhập dữ liệu thành công";

                string connectionString = @"Data Source=FOX-PC\SQLEXPRESS;Initial Catalog=Project;Integrated Security=True";
                SqlConnection conn = new SqlConnection(connectionString);
                string sql = "insert into LIENHE(tenkhachhang,email,ngaylienhe,tieude,noidung) values (@tenkh,@email,@ngay,@tieude,@noidung)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@tenkh", tenkhachhang.Text);
                cmd.Parameters.AddWithValue("@email", email.Text);
                cmd.Parameters.AddWithValue("@ngay", DateTime.Today);
                cmd.Parameters.AddWithValue("@tieude", tieude.Text);
                cmd.Parameters.AddWithValue("@noidung", noidung.Text);

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }


        }
    }
}